package com.gmj.controller;


import com.gmj.entity.Class;
import com.gmj.entity.Health;
import com.gmj.entity.Laboratory;
import com.gmj.entity.LaboratoryHealth;
import com.gmj.service.IHealthService;
import com.gmj.service.ILaboratoryHealthService;
import com.gmj.service.ILaboratoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmj
 * @since 2022-01-29
 */
@RestController
@RequestMapping("/laboratoryHealth")
public class LaboratoryHealthController {
    @Autowired
    private ILaboratoryHealthService hs;
    @Autowired
    private ILaboratoryService ls;
    @GetMapping("/selectAll")
    public List<LaboratoryHealth> selectAll(){
        List<LaboratoryHealth> list = hs.list();
        List<Laboratory> laboratoryList = ls.list();
        list=list.stream().peek((lh)->{
            Laboratory laboratory= laboratoryList.stream().filter((l) -> lh.getLid() == l.getId()).collect(Collectors.toList()).get(0);
            lh.setLaboratory(laboratory);
        }).collect(Collectors.toList());
        return list;
    }
    @PostMapping("/add")
    public void add(@RequestBody LaboratoryHealth health){
        hs.save(health);
    }

    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") int id){
        hs.removeById(id);
    }
}

